<template>
  <div>
    <el-button @click="delVolume" size="small" icon="el-icon-delete" type="danger">{{$t('NetBtn_delete')}}</el-button>
    <el-button @click="addVolume" size="small" icon="el-icon-circle-plus-outline" type="success">{{$t('NetBtn_Addnetwork')}}</el-button>
  </div>
</template>

<script>
import post from '@/utils/post'
export default {
  props: ['checkNet'],
  methods: {
    // 添加
    addVolume () {
      this.$router.push('/Network/AddNet')
    },
    // 删除数据卷
    delVolume () {
      if (this.checkNet.length < 1) {
        return this.$message({
          showClose: true,
          message: '未选择数据卷！',
          type: 'warning'
        })
      }
      for (let a = 0; a < this.checkNet.length; a++) {
        const docker = `curl -w %{http_code} --unix-socket /var/run/docker.sock -s -X DELETE "http:/v1.40/networks/${this.checkNet[a].Name}"` // 删除网络
        post({ docker }, res => {
          if (res.message) {
            return this.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
          }
          this.$message({
            showClose: true,
            message: '数据卷删除成功！',
            type: 'success'
          })
          this.$emit('successDel')
        }, this)
      }
    }
  }
}
</script>
